package com.xm_jd.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.IndexDao;
import com.xm_jd.model.entitys.shoop;
import com.xm_jd.utils.BaseServlet;

/**
 * Servlet implementation class ShoopsListServlet
 */
@WebServlet("/shooplist")
public class ShoopsListServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShoopsListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//����������ű���
				//�����ݿ��ѯ����������Ϣ
				IndexDao ndao = new IndexDao();
				String c = request.getParameter("currentpage");
				//��ǰҳ��
				int current = c==null ? 1 : Integer.parseInt(c);
				//ҳ��С
				int pagesize = 3;
				List<shoop> list = ndao.getNewsList(current,pagesize);
				//��ѯ���м�¼���Լ���ҳ��
				int total = ndao.getTotalNews();
				//������ҳ��
				//int pages = total%pagesize==0 ? total/pagesize : total/pagesize+1;
				//���������
				request.setAttribute("list", list);
				request.setAttribute("total", total);
				request.setAttribute("currentpage", current);
				//ת��
				//request.getRequestDispatcher("jsps/index.jsp").forward(request, response);;
				this.forward("index");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
